import { MESSAGE_TYPE } from '../common/enums'
import request from '../common/request'

export interface IMessageRequest {
  atUserIds: number[]
  content: string
  groupId?: number
  recvId?: number
  type: MESSAGE_TYPE
}

// content:"123"
// id:1
// recvId:2
// sendId:1
// sendTime:1706694510000
// status:3
// type:0

const getPrivateMessages = (id: number) => {
  return request({
    url: `/message/private/loadMessage?minId=${id}`,
    method: 'GET'
  })
}

const getGroupMessages = (id: number) => {
  return request({
    url: `/message/group/loadMessage?minId=${id}`,
    method: 'GET'
  })
}

const getPrivateMessagesReaded = (id: number) => {
  return request({
    url: `/message/private/maxReadedId?friendId=${id}`,
    method: 'GET'
  })
}

const getGroupMessagesReaded = (data: any) => {
  return request({
    url: '/message/group/readed',
    method: 'PUT',
    data
  })
}

const recallPrivateMessage = (id: number) => {
  return request({
    url: `/message/private/recall/${id}`,
    method: 'DELETE'
  })
}

const recallGroupMessage = (id: number) => {
  return request({
    url: `/message/group/recall/${id}`,
    method: 'DELETE'
  })
}

const sendPrivateMessage = (data: IMessageRequest) => {
  return request({
    url: `/message/private/send`,
    method: 'POST',
    data
  })
}

const sendGroupMessage = (data: IMessageRequest) => {
  return request({
    url: `/message/group/send`,
    method: 'POST',
    data
  })
}

export const messageApi = {
  getPrivateMessages,
  getGroupMessages,
  getPrivateMessagesReaded,
  getGroupMessagesReaded,
  recallPrivateMessage,
  recallGroupMessage,
  sendPrivateMessage,
  sendGroupMessage
}